package adminService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/config"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/response"
	"gitee.com/yangguoliang001/go-gin-vue3/util/code"
	"gitee.com/yangguoliang001/go-gin-vue3/vo"
	"github.com/gin-gonic/gin"
)

func (a *AdminService) Logout(c *gin.Context) (res vo.LogoutVO, err error) {
	signToken := c.GetHeader(config.HeaderLoginToken)
	token := signToken[7:]
	if b := a.cache.Del(config.RedisKeyPrefixLoginUser + token); b.Val() == 0 {
		// 退出登录失败
		response.Fail(c, code.AdminLogOutError, code.Text(code.AdminLogOutError), gin.H{"realErr": b.Err()})
		return vo.LogoutVO{}, b.Err()
	}
	return vo.LogoutVO{
		Logout: true,
	}, nil
}
